/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-01-28
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-03-01
 * @Description: 添加好友页面
 */
import 'package:chat_client/providers/application_provider.dart';
import 'package:flutter/material.dart';
import 'package:chat_client/widgets/custom_global_widgets.dart';
import 'package:provider/provider.dart';

class AddFriendScreen extends StatelessWidget {
  const AddFriendScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('添加朋友')),
      backgroundColor: Color(0xFFEDEDED),
      body: ChangeNotifierProvider(
        create: (_) => ApplicationProvider(),
        child: Consumer<ApplicationProvider>(builder: (context, model, child) {
          return ListView(
            children: [
              CListTile(
                icon: Icons.person_add,
                iconColor: Colors.white,
                backgroundColor: Colors.amberAccent,
                title: '好友申请',
                onTap: () => model.navToNewFriends(),
                trailing: Icon(Icons.chevron_right),
              ),
              Divider(height: 1),
              CListTile(
                title: '黑名单',
                icon: Icons.block,
                iconColor: Colors.white,
                backgroundColor: Colors.black,
                onTap: () => model.navToBlockList(),
                trailing: Icon(Icons.chevron_right),
              ),
              DividerWithText(text: '搜索'),
              Container(
                padding: EdgeInsets.all(20),
                decoration: BoxDecoration(
                  color: Colors.white,
                ),
                child: TextField(
                  controller: model.searchController,
                  decoration: InputDecoration(
                    hintText: '账号/手机号',
                    prefixIcon: Icon(Icons.search),
                    contentPadding: const EdgeInsets.only(left: 16.0),
                  ),
                  onChanged: (_) => model.handleSearchInput(),
                ),
              ),
              DividerWithText(text: ''),
              model.showSearchBtu
                  ? CListTile(
                      title: '',
                      titleWidget: Row(
                        children: [
                          Text('搜索:'),
                          SizedBox(width: 10),
                          Expanded(
                            child: Text(model.searchText,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  fontSize: 20,
                                  color: Color(0XFF2EA245),
                                )),
                          ),
                        ],
                      ),
                      icon: Icons.person_search,
                      iconColor: Colors.white,
                      backgroundColor: Color(0XFF2EA245),
                      minTileHeight: 80,
                      iconborderRadius: 2,
                      iconSize: 58,
                      onTap: () => model.handleSearch(context))
                  : SizedBox(),
            ],
          );
        }),
      ),
    );
  }
}
